//
//  LivePictureTableViewCell.m
//  LiveSoftware
//
//  Created by lanou3g on 15/7/24.
//  Copyright (c) 2015年 lanou3g. All rights reserved.
//

#import "LivePictureTableViewCell.h"

@implementation LivePictureTableViewCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // 主队
        CGFloat gap = kScreenIp6(10);
        CGFloat height = kScreenIp6(20);
        CGFloat homeTeamInfoW = kScreenIp6(100);
        CGFloat homeTeamInfoH = kScreenIp6(70);
        self.homeTeamInfo = [[UIView alloc] initWithFrame:CGRectMake(gap, height, homeTeamInfoW, homeTeamInfoH)];
//                self.homeTeamInfo.backgroundColor = [UIColor redColor];
        [self.contentView addSubview:_homeTeamInfo];
        
        CGFloat homeTeamLogoW = kScreenIp6(50);
        CGFloat homeTeamLogoX = (homeTeamInfoW - homeTeamLogoW) / 2;
        
        self.homeTeamLogo = [[UIImageView alloc] initWithFrame:CGRectMake(homeTeamLogoX, 0, homeTeamLogoW, homeTeamLogoW)];
        self.homeTeamLogo.image = [UIImage imageNamed:@"zhudui_1"];
        [self.homeTeamInfo addSubview:_homeTeamLogo];
        
        CGFloat homeTeamY = CGRectGetMaxY(_homeTeamLogo.frame);
        CGFloat homeTeamH = homeTeamInfoH - homeTeamLogoW;
        self.homeTeam = [[UILabel alloc] initWithFrame:CGRectMake(0, homeTeamY, homeTeamInfoW, homeTeamH)];
        self.homeTeam.text = @"主队";
        _homeTeam.font = [UIFont systemFontOfSize:12];
        _homeTeam.textAlignment = NSTextAlignmentCenter;
        [self.homeTeamInfo addSubview:_homeTeam];
        
        // 客队
        CGFloat visitTeamInfoX = kScreenWidth - gap - homeTeamInfoW;
        CGFloat visitTeamInfoW = kScreenIp6(100);
        self.visitTeamInfo = [[UIView alloc] initWithFrame:CGRectMake(visitTeamInfoX, height, homeTeamInfoW, homeTeamInfoH)];
        //        self.visitTeamInfo.backgroundColor = [UIColor redColor];
        [self.contentView addSubview:_visitTeamInfo];
        
        
        self.visitTeamLogo = [[UIImageView alloc] initWithFrame:CGRectMake(homeTeamLogoX, 0, homeTeamLogoW, homeTeamLogoW)];
        self.visitTeamLogo.image = [UIImage imageNamed:@"zhudui_1"];
        
        [self.visitTeamInfo addSubview:_visitTeamLogo];
        
        self.visitTeam = [[UILabel alloc] initWithFrame:CGRectMake(0, homeTeamY, homeTeamInfoW, homeTeamH)];
        _visitTeam.text = @"客队";
        _visitTeam.font = [UIFont systemFontOfSize:12];
        
        _visitTeam.textAlignment = NSTextAlignmentCenter;
        [self.visitTeamInfo addSubview:_visitTeam];
        
        
        // 比赛信息宽度根据主客队宽度计算
        CGFloat matchInfoX = CGRectGetMaxX(_homeTeamInfo.frame) + gap;
        CGFloat matchInfoW = kScreenWidth - homeTeamInfoW - visitTeamInfoW - gap * 4;
        self.matchInfo = [[UIView alloc] initWithFrame:CGRectMake(matchInfoX, height / 2, matchInfoW, homeTeamInfoH + gap)];
        //        self.matchInfo.backgroundColor = [UIColor redColor];
        [self.contentView addSubview:_matchInfo];
        
        CGFloat matchW = matchInfoW;
        CGFloat matchH = kScreenIp6(20);
        self.match = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, matchW, matchH)];
        self.match.textAlignment = NSTextAlignmentCenter;
        self.match.text = @"中超";
        //        self.match.backgroundColor = [UIColor yellowColor];
        _match.font = [UIFont systemFontOfSize:12];
        
        [self.matchInfo addSubview:_match];
        
        CGFloat attentionW = kScreenIp6(40);
        CGFloat attentionX = (matchInfoW - attentionW) / 2;
        CGFloat attentionY = CGRectGetMaxY(_match.frame);
        self.attention = [UIButton buttonWithType:UIButtonTypeSystem];
        //        self.attention.backgroundColor = [UIColor redColor];
        self.attention.frame = CGRectMake(attentionX, attentionY, attentionW, attentionW);
        [self.matchInfo addSubview:_attention];
        
        CGFloat channeY = CGRectGetMaxY(_attention.frame);
        CGFloat channeH = kScreenIp6(20);
        self.channe = [[UILabel alloc] initWithFrame:CGRectMake(0, channeY, matchInfoW, channeH)];
        //        self.channe.backgroundColor = [UIColor orangeColor];
        self.channe.text = @"CCTV 5";
        _channe.font = [UIFont systemFontOfSize:12];
        
        self.channe.textAlignment = NSTextAlignmentCenter;
        [self.matchInfo addSubview:_channe];
        
        //线
        UIView *footLineView = [[UIView  alloc]initWithFrame:CGRectMake( 0, kScreenIp6(100-1), kScreenWidth, 0.5)];
        
        footLineView.backgroundColor = [UIColor colorWithWhite:0.699 alpha:1.000];
        
        // 设置 cell 点击没有变化
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        [self addSubview:footLineView];
    }
    return self;
}

- (void)setDataWithModel:(ListArrayModel *)model
{
    
    // 主队logo
    NSString *homeTeamLogo = [@"%2f" stringByAppendingString:model.home_logo];
    NSString *homeLogoUrl = [NSString stringWithFormat:@"http://duihui.oss-cn-hangzhou.aliyuncs.com/zuqiu%@.png",homeTeamLogo];
    // 客队logo
    NSString *visitTeamLogo = [@"%2f" stringByAppendingString:model.visit_logo];
    NSString *visitLogoUrl = [NSString stringWithFormat:@"http://duihui.oss-cn-hangzhou.aliyuncs.com/zuqiu%@.png",visitTeamLogo];
    
    // 时间和比赛类型拼接
    NSString *match = [NSString stringWithFormat:@"%@ %@",model.time,model.matchProperty];
    
    // 主队
    [self.homeTeamLogo setImageWithURL:[NSURL URLWithString:homeLogoUrl] placeholderImage:[UIImage imageNamed:@"zhudui_1"]];
    // 客队
    [self.visitTeamLogo setImageWithURL:[NSURL URLWithString:visitLogoUrl] placeholderImage:[UIImage imageNamed:@"kedui_2"]];
    self.visitTeam.text = model.visit_team;
    self.homeTeam.text = model.home_team;
    // 比赛信息
    self.match.text = match;
    if ([model.keywords isEqualToString:@""]) {
        self.channe.text = @"比分直播";
    }
    else
    {
        self.channe.text = model.keywords;
    }
}


@end
